package com.ylong.mapper;

import com.ylong.entity.Course;
import com.ylong.entity.GenderEnum;
import com.ylong.entity.Student;
import com.ylong.vo.StudentVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.List;

/**
 * StudentMapper:${DESCRIPTION}
 *
 * @author: zhaoyl
 * @date: 2020/12/10
 */
@Mapper
public interface StudentMapper {
    StudentMapper INSTANCE = Mappers.getMapper(StudentMapper.class);

    @Mapping(source = "gender.name", target = "gender")
    @Mapping(source = "birthday", target = "birthday", dateFormat = "yyyy-MM-dd HH:mm:ss")
    StudentVO student2StudentVO(Student student);

    //可以手动指定格式化的方法就不需要@Mapping映射
//    default String getGenderName(GenderEnum gender) {
//        return gender.getName();
//    }

    List<StudentVO> students2StudentVOs(List<Student> studentList);

    @Mapping(source = "student.gender.name", target = "gender")
    @Mapping(source = "student.birthday", target = "birthday", dateFormat = "yyyy-MM-dd HH:mm:ss")
    @Mapping(source = "course.courseName", target = "course")
    @Mapping(source = "student.name", target = "name", defaultValue = "张三")
    StudentVO studentAndCourse2StudentVO(Student student, Course course);

}
